<?php

namespace common\models\db;

use Yii;

/**
 * This is the model class for table "tbl_commercial_loan_detail".
 *
 * @property int $id
 * @property int $record_id 关联的贷款记录ID
 * @property float $amount 商业贷款金额(万元)
 * @property float $rate 商业贷款利率(%)
 * @property int|null $basis_points 基点调整
 * @property float $adjusted_rate 调整后的利率(%)
 *
 * @property LoanRecord $loanRecord
 */
class CommercialLoanDetail extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'tbl_commercial_loan_detail';
    }

    /**
     * {@inheritdoc}
     */
    public function attributes()
    {
        return [
            'id',
            'record_id',
            'amount',
            'rate',
            'basis_points',
            'adjusted_rate'
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['record_id', 'amount', 'rate', 'adjusted_rate'], 'required'],
            [['record_id', 'basis_points'], 'integer'],
            [['amount', 'rate', 'adjusted_rate'], 'number'],
            [['record_id'], 'unique'],
            [['record_id'], 'exist', 'skipOnError' => true, 'targetClass' => LoanRecord::class, 'targetAttribute' => ['record_id' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'record_id' => 'Loan Record ID',
            'amount' => 'Amount',
            'rate' => 'Rate',
            'basis_points' => 'Basis Points',
            'adjusted_rate' => 'Adjusted Rate',
        ];
    }

    /**
     * Gets query for [[LoanRecord]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getLoanRecord()
    {
        return $this->hasOne(LoanRecord::class, ['id' => 'record_id']);
    }
}
